import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'nprogress'
Vue.use(VueRouter)

const home = r => require.ensure([], () => r(require('@/views/Home')))
const login = r => require.ensure([], () => r(require('@/views/passport/login')))
const register = r => require.ensure([], () => r(require('@/views/passport/register')))
const emailRegister = r => require.ensure([], () => r(require('@/views/passport/email')))
const forget = r => require.ensure([], () => r(require('@/views/passport/forget')))

const examIndex = r => require.ensure([], () => r(require('@/views/exam/index')))
const examList = r => require.ensure([], () => r(require('@/views/exam/list')))
const examTesting = r => require.ensure([], () => r(require('@/views/exam/testing')))
const balloonGame = r => require.ensure([], () => r(require('@/views/game/balloon')))
const shopIndex = r => require.ensure([], () => r(require('@/views/shop/index')))
const orderList = r => require.ensure([], () => r(require('@/views/order/list')))
const orderDetail = r => require.ensure([], () => r(require('@/views/order/detail')))
const recommendOrderList = r => require.ensure([], () => r(require('@/views/order/recommendOrderList')))
const userIndex = r => require.ensure([], () => r(require('@/views/user/index')))

const routes = [
	{
		path: "*",
		redirect: "/",
	},
	{
		path: '/',
		name: 'home',
		component: home,
		meta: {
			des: false
		}
	},
	{
		path: '/passport/login',
		name: 'login',
		component: login,
		meta: {
			des: false
		}
	},
	{
		path: '/passport/register',
		name: 'register',
		component: register,
		meta: {
			des: false
		}
	},
	{
		path: '/passport/email',
		name: 'register-email',
		component: emailRegister,
		meta: {
			des: false
		}
	},
	{
		path: '/passport/forget',
		name: 'forget',
		component: forget,
		meta: {
			des: false
		}
	},
	{
		path: '/exam/index',
		name: 'exam-index',
		component: examIndex,
		meta: {
			des: true
		}
	},
	{
		path: '/exam/list',
		name: 'exam-list',
		component: examList,
		meta: {
			des: true
		}
	},
	{
		path: '/exam/testing/:id',
		name: 'exam-testing',
		component: examTesting,
		meta: {
			des: true
		}
	},
	{
		path: '/game/balloon',
		name: 'game-balloon',
		component: balloonGame,
		meta: {
			des: true
		}
	},
	{
		path: '/shop/index',
		name: 'shop-index',
		component: shopIndex,
		meta: {
			des: true
		}
	},
	{
		path: '/order/list',
		name: 'order-list',
		component: orderList,
		meta: {
			des: true
		}
	},
	{
		path: '/order/detail',
		name: 'order-detail',
		component: orderDetail,
		meta: {
			des: true
		}
	},
	{
		path: '/order/recommendOrderList',
		name: 'order-recommend',
		component: recommendOrderList,
		meta: {
			des: true
		}
	},
	{
		path: '/user/index',
		name: 'user-index',
		component: userIndex,
		meta: {
			des: true
		}
	},
]

const router = new VueRouter({
	mode: 'hash',
	base: process.env.BASE_URL,
	routes
})
router.beforeEach((to, from, next) => {
	NProgress.start()
	next()
})
router.afterEach(transition => {
	NProgress.done()
})
export default router
